package com.leessy.r229.utils;

import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;

import java.lang.reflect.Method;

/**
 * @author : Created by liucheng. on 2021/6/17
 * @description : -
 */
public class DevicesBootUtil {
    public static void reboot(Context context) {
        Intent intent = new Intent(Intent.ACTION_REBOOT);
        intent.putExtra("nowait", 1);
        intent.putExtra("interval", 1);
        intent.putExtra("window", 0);
        context.sendBroadcast(intent);
    }

    public static void shutDowm(Context context) {
        try {
            PowerManager pManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            Method shutdown = pManager.getClass().getMethod("shutdown", boolean.class, String.class, boolean.class);
            //调用shutdown()方法
            shutdown.invoke(pManager, false, "", true);
        } catch (Exception e) {
        }
    }
}
